package com.hotelsystem.reservations.main;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import com.hotelsystem.reservations.clientvalidation.ClientValidation;
import com.hotelsystem.reservations.constants.Constants;
import com.hotelsystem.reservations.hotels.Hotel;
import com.hotelsystem.reservations.hotels.HotelInformation;
import com.hotelsystem.reservations.persons.Client;
import com.hotelsystem.reservations.persons.ClientManagement;
import com.hotelsystem.reservations.persons.GenderEnum;
import com.hotelsystem.reservations.reservations.CurrentReservationsScheduler;
import com.hotelsystem.reservations.reservations.FutureReservationsScheduler;
import com.hotelsystem.reservations.reservations.Reservation;
import com.hotelsystem.reservations.reservations.ReservationDetails;
import com.hotelsystem.reservations.reservations.ReservationManagement;
import com.hotelsystem.reservations.reservations.ReservationStatusEnum;
import com.hotelsystem.reservations.rooms.Room;
import com.hotelsystem.reservations.rooms.RoomManagement;
import com.hotelsystem.reservations.rooms.RoomTypesEnum;

public class HotelSystemMainProgram {

	public static void main(String[] args) throws ParseException {
		// TODO Auto-generated method stub

		// HotelInformation hotelInformation = new HotelInformation("Hotel",
		// "Planet Earth", "*******", "Best hotel",
		// true, true, true, true, true, true, true, true, true);
		//
		// ArrayList<Room> rooms = new ArrayList<Room>();
		//
		// Room room1 = new Room(1, RoomTypesEnum.PRESIDENTIAL_SUITE, true);
		// Room room2 = new Room(2, RoomTypesEnum.LUXE_SUITE, true);
		// Room room3 = new Room(3, RoomTypesEnum.ONE_PERSON_ROOM, false);
		// Room room4 = new Room(4, RoomTypesEnum.SUITE, false);
		// Room room5 = new Room(5, RoomTypesEnum.TWO_PERSONS_ROOM, false);
		//
		// rooms.add(room1);
		// rooms.add(room2);
		// rooms.add(room3);
		// rooms.add(room4);
		// rooms.add(room5);
		//
		// ArrayList<Reservation> reservations = new ArrayList<Reservation>();
		//
		// Hotel hotel = new Hotel(hotelInformation, rooms, reservations);
		//
		// ReservationDetails reservationDetails = new
		// ReservationDetails(RoomTypesEnum.LUXE_SUITE, true, false, true,
		// ReservationStatusEnum.NEW_RESERVATION);
		//
		// Client client = new Client("John", "Doe", "777", "1234",
		// GenderEnum.MALE, 23, "john.doe@mail.bg", "Bulgarian",
		// reservationDetails);
		//
		// System.out.println("Client: " + client);
		//
		// SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
		// Date startDate = df.parse("17-05-2015");
		// Date endDate = df.parse("19-05-2015");
		//
		// Room roomForReservation = reservationDetails.getRoomByDetails(rooms,
		// startDate, endDate, reservations);
		// if (roomForReservation != null) {
		// Reservation reservation = new Reservation(startDate, endDate, client,
		// reservationDetails.getRoomByDetails(
		// rooms, startDate, endDate, reservations));
		//
		// client.getReservationDetails().confirmReservation(reservation,
		// hotel);
		// }
		//
		// reservations = hotel.getReservations();
		//
		// System.out.println("First iteration:");
		// for (Reservation res : reservations) {
		// System.out.println(res);
		// }
		//
		// startDate = df.parse("20-05-2015");
		// endDate = df.parse("21-05-2015");
		//
		// if (roomForReservation != null) {
		// Reservation reservation = new Reservation(startDate, endDate, client,
		// reservationDetails.getRoomByDetails(
		// rooms, startDate, endDate, reservations));
		//
		// client.getReservationDetails().confirmReservation(reservation,
		// hotel);
		// }
		//
		// reservations = hotel.getReservations();
		//
		// System.out.println("Second iteration:");
		// for (Reservation res : reservations) {
		// System.out.println(res);
		// }
		//
		//
		ArrayList <Client> clientList = new ArrayList<Client>();
		SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
		Date startDate = df.parse("17-05-2015");
		Date endDate = df.parse("19-05-2015");
		Date startDate2 = df.parse("22-05-2015");
		Date endDate2 = df.parse("25-05-2015");
		ReservationDetails reservationDetails = new ReservationDetails(RoomTypesEnum.LUXE_SUITE, true, false, true,
				ReservationStatusEnum.NEW_RESERVATION, clientList);
		ReservationDetails reservationDetails2 = new ReservationDetails(RoomTypesEnum.PRESIDENTIAL_SUITE, true, true, true,
				ReservationStatusEnum.NEW_RESERVATION, clientList);
		
		Client client = new Client("John", "Doe", "777", "1234", GenderEnum.MALE, 23, "john.doe@mail.bg", "Bulgarian",
				null, reservationDetails);
		Client client2 = new Client("Donny", "Brasco", "888", "0000", GenderEnum.MALE, 40, "donny.brasco@mail.bg", "Sicilian",
				null, reservationDetails2);
		
		ClientManagement clientManagement = new ClientManagement();
		boolean isSave = clientManagement.addClientInFile(client);
		System.out.println("Is first client saved:" + isSave);
		isSave = clientManagement.addClientInFile(client2);
		System.out.println("Is second client saved:" + isSave);
		
		ArrayList<Room> rooms = new ArrayList<Room>();

		Room room1 = new Room(1, RoomTypesEnum.PRESIDENTIAL_SUITE, true);
		Room room2 = new Room(2, RoomTypesEnum.LUXE_SUITE, true);
		Room room3 = new Room(3, RoomTypesEnum.ONE_PERSON_ROOM, false);
		Room room4 = new Room(4, RoomTypesEnum.SUITE, false);
		Room room5 = new Room(5, RoomTypesEnum.TWO_PERSONS_ROOM, false);

		rooms.add(room1);
		rooms.add(room2);
		rooms.add(room3);
		rooms.add(room4);
		rooms.add(room5);
		HotelInformation hotelInformation = new HotelInformation("Hotel", "Planet Earth", "*******", "Best hotel",
				true, true, true, true, true, true, true, true, true);
		ArrayList<Reservation> reservations = new ArrayList<Reservation>();
		Hotel hotel = new Hotel(hotelInformation, rooms, reservations);
		// check reservation management
		ReservationManagement reservationManagement = new ReservationManagement();
		reservationManagement.createReservation(startDate, endDate, client, hotel);
		reservationManagement.createReservation(startDate2, endDate2, client2, hotel);
		System.out.println(hotel.getReservations());

		reservationManagement.removeReservation(hotel.getReservations().get(0), hotel);
		System.out.println(hotel.getReservations());
		// check room management
		RoomManagement roomManagement = new RoomManagement();
		roomManagement.addRoom(room1, hotel);
		room1.setSmokersFree(!room1.isSmokersFree());
		roomManagement.updateRoomDetails(room1, hotel);
		System.out.println("number of rooms: " + hotel.getRooms().size());
		roomManagement.removeRoom(room1, hotel);
		System.out.println("number of rooms: " + hotel.getRooms().size());

		FutureReservationsScheduler futureReservationsScheduler = new FutureReservationsScheduler(60000, Constants.FUTURE_RESERVATIONS_PATH, Constants.CURRENT_RESERVATIONS_PATH);
		CurrentReservationsScheduler currentReservationsScheduler = new CurrentReservationsScheduler(60000, Constants.CURRENT_RESERVATIONS_PATH, Constants.PAST_RESERVATIONS_PATH);
		
		futureReservationsScheduler.startMechanisme();
		currentReservationsScheduler.startMechanisme();

		

	}
}
